package com.hssy.stationtv;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;

public class StationTwoDialog extends Dialog {

    public StationTwoDialog(Context context) {
        super(context);
    }

    public StationTwoDialog(Context context, int theme) {
        super(context, theme);
    }

    public static class Builder {
    	private Context context;
        private String station2ButtonText;
        private String setting2ButtonText;
        private DialogInterface.OnClickListener station2ButtonClickListener;
        private DialogInterface.OnClickListener setting2ButtonClickListener;

        public Builder(Context context) {
            this.context = context;
        }
  
        /**
         * Set the positive button resource and it's listener
         *
         * @param positiveButtonText
         * @return
         */
        public Builder setPositiveButton(int station2ButtonText,
                DialogInterface.OnClickListener listener) {
            this.station2ButtonText = (String) context.getText(station2ButtonText);
            this.station2ButtonClickListener = listener;
            return this;
        }

        public Builder setPositiveButton(String station2ButtonText,
                DialogInterface.OnClickListener listener) {
            this.station2ButtonText = station2ButtonText;
            this.station2ButtonClickListener = listener;
            return this;
        }
  
        public Builder setNegativeButton(int setting2ButtonText,
                DialogInterface.OnClickListener listener) {
            this.setting2ButtonText = (String) context
            		.getText(setting2ButtonText);
            this.setting2ButtonClickListener = listener;
            return this;
        }

        public Builder setNegativeButton(String setting2ButtonText,
                DialogInterface.OnClickListener listener) {
            this.setting2ButtonText = setting2ButtonText;
            this.setting2ButtonClickListener = listener;
            return this;
        }

        @SuppressLint("InflateParams") 
        public StationTwoDialog create() {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final StationTwoDialog dialog = new StationTwoDialog(context,R.style.Dialog);
            View layout = inflater.inflate(R.layout.dialog_station2, null);
            dialog.addContentView(layout, new LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            // set the confirm button
            if (station2ButtonText != null) {
                ((Button) layout.findViewById(R.id.station2Button))
                        .setText(station2ButtonText);
                if (station2ButtonClickListener != null) {
                    ((Button) layout.findViewById(R.id.station2Button))
                            .setOnClickListener(new View.OnClickListener() {
                                public void onClick(View v) {
                                	station2ButtonClickListener.onClick(dialog,
                                            DialogInterface.BUTTON_POSITIVE);
                                }
                            });
                }
            } else {
                // if no confirm button just set the visibility to GONE
                layout.findViewById(R.id.station2Button).setVisibility(
                        View.GONE);
            }
            if (setting2ButtonText != null) {
                ((Button) layout.findViewById(R.id.setting2Button))
                        .setText(setting2ButtonText);
                if (setting2ButtonClickListener != null) {
                    ((Button) layout.findViewById(R.id.setting2Button))
                            .setOnClickListener(new View.OnClickListener() {
                                public void onClick(View v) {
                                	setting2ButtonClickListener.onClick(dialog,
                                            DialogInterface.BUTTON_NEGATIVE);
                                }
                            });
                }
            } else {
                // if no confirm button just set the visibility to GONE
                layout.findViewById(R.id.setting2Button).setVisibility(
                        View.GONE);
            }
            dialog.setContentView(layout);
            return dialog;
        }
    }
}